import { Select, DatePicker, Input, TimePicker } from 'antd';
import { tradingList, clickhouseList } from './service';
import { Tooltip } from 'antd';

const { TextArea } = Input;

async function getTradingCenterNameList() {
  const { data } = await tradingList();
  return data;
}

async function getClickHouseList() {
  const { data } = await clickhouseList();
  return data;
}

export const COMPANY_TABLE_COLUMNS_LIST = () => {
  return [
    {
      name: '序号',
      code: 'id',
      width: 60,
      render: (value) => {
        return value || '--';
      },
    },
    {
      name: '公司编码',
      code: 'companyCode',
      width: 300,
      render: (value) => {
        return value || '--';
      },
    },
    {
      name: '公司名称',
      code: 'companyName',
      width: 560,
      render: (value) => {
        return value || '--';
      },
    },
  ];
};

export const MODULE_TABLE_COLUMNS_LIST = () => {
  return [
    {
      name: '序号',
      code: 'id',
      width: 60,
      render: (value) => {
        return value || '--';
      },
    },
    {
      name: '执行模块编码',
      code: 'grabModuleCode',
      width: 300,
      render: (value) => {
        return value || '--';
      },
    },
    {
      name: '执行模块名称',
      code: 'grabModuleName',
      width: 560,
      render: (value) => {
        return value || '--';
      },
    },
  ];
};

export const TASK_LOG_LIST = ({ showLogViewDrawer }) => {
  return [
    {
      name: '序号',
      code: 'id',
      width: 60,
      render: (value) => {
        return value || '--';
      },
    },
    {
      name: '执行节点',
      code: 'taskNodeName',
      width: 100,
      render: (value) => {
        return value || '--';
      },
    },
    {
      name: '创建时间',
      code: 'createdAt',
      width: 100,
      render: (value) => {
        return value || '--';
      },
    },
    {
      name: '内容',
      code: 'taskContent',
      width: 60,
      /*  render: (value) => {
        return (
          (
            <Tooltip title={value}>
              <div style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
                {value}
              </div>
            </Tooltip>
          ) || '--'
        );
      }, */
      render: (value, record, rowIndex) => {
        return (
          // <Tooltip title={'实例日志内容过多，请点击查看！'}>
          <div style={{ display: 'flex' }}>
            <span key="select" data-operate="operate" onClick={() => showLogViewDrawer(value)}>
              {'内容查看'}
            </span>
          </div>
          // </Tooltip>
        );
      },
    },
  ];
};

export const actuatorTypeList = [
  { label: '交易中心', value: 'TradingCenter' },
  { label: '公众号', value: 'OfficialAccount' },
];

export const priorityLevelList = [
  { label: '最高级', value: 'HIGHEST' },
  { label: '高级', value: 'HIGH' },
  { label: '中级', value: 'MEDIUM' },
  { label: '低级', value: 'LOW' },
  { label: '最低级', value: 'LOWEST' },
];

export const retryStatusList = [
  { label: '否', value: false },
  { label: '是', value: true },
];

export const dataStateList = [
  { label: '启用', value: 1 },
  { label: '禁用', value: 0 },
];

export const tradingCenterNameList = await getTradingCenterNameList();

export const clickHouseList = await getClickHouseList();

export const retryTypeList = [
  { label: '直接重试', value: 'DirectedRetry' },
  { label: '间隔重试', value: 'IntervalRetry' },
];

export const CREATE_LINKED_FORM_ITEM_LIST = [
  {
    infoTitle: '基本信息',
    list: [
      {
        label: '任务编号',
        type: 'input',
        components: Input,
        key: 'taskId',
        width: '297px',
        attrs: {
          disabled: true,
          allowClear: true,
          placeholder: '暂时不用输入',
        },
      },
      {
        label: '执行器类型',
        type: 'select',
        components: Select,
        options: actuatorTypeList,
        key: 'actuatorTypeCode',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '交易中心名称',
        type: 'select',
        components: Select,
        options: tradingCenterNameList,
        key: 'tradingCenterCode',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '任务名称',
        type: 'input',
        components: Input,
        key: 'taskName',
        width: '297px',
        rules: [
          { required: true, message: '请输入' },
          {
            pattern: /^.{2,20}$/,
            message: '输入名称最大20个字符,最小2个字符',
          },
        ],
        attrs: {
          allowClear: true,
          placeholder: '请输入',
        },
      },
      {
        label: '优先等级',
        type: 'select',
        components: Select,
        options: priorityLevelList,
        key: 'priority',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '超时时间',
        type: 'input',
        components: Input,
        key: 'timeOut',
        width: '297px',
        rules: [{ required: true, message: '请输入超时时间' }],
        attrs: {
          placeholder: '请输入',
          allowClear: true,
        },
      },
      {
        label: '重复周期',
        type: 'input',
        components: Input,
        key: 'cronTime',
        width: '297px',
        rules: [{ required: true, message: '请配置重复周期' }],
        attrs: {
          placeholder: '请配置重复周期',
          allowClear: true,
        },
      },
      {
        label: '数据处理状态',
        type: 'select',
        components: Select,
        options: dataStateList,
        rules: [{ required: true, message: '请选择' }],
        key: 'valid',
        width: '297px',
        attrs: {
          placeholder: '请选择',
          allowClear: true,
        },
      },
      {
        label: '表名',
        type: 'input',
        components: Input,
        key: 'dataName',
        rules: [{ required: true, message: '请输入' }],
        width: '297px',
        attrs: {
          placeholder: '请输入',
          allowClear: true,
        },
      },
      {
        label: '校验字段',
        type: 'input',
        components: Input,
        key: 'checkField',
        rules: [{ required: true, message: '请输入' }],
        width: '297px',
        attrs: {
          placeholder: '请输入',
          allowClear: true,
        },
      },
      {
        label: '唯一性字段',
        type: 'input',
        components: Input,
        key: 'deleteField',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          placeholder: '请输入',
          allowClear: true,
        },
      },
      {
        label: '入库表名',
        type: 'select',
        components: Select,
        options: clickHouseList,
        key: 'clickhouseName',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '备注',
        type: 'textArea',
        components: TextArea,
        key: 'taskDesc',
        width: '297px',
        height: '34px',
        attrs: {
          placeholder: '请输入',
        },
      },
      {
        label: '执行脚本',
        type: 'textArea',
        components: TextArea,
        key: 'executeScript',
        minWidth: '1064px',
        attrs: {
          placeholder: '请输入',
          autoSize: { minRows: 3, maxRows: 8 },
        },
      },
    ],
  },
  {
    infoTitle: '重试信息',
    list: [
      {
        label: '是否重试',
        type: 'select',
        components: Select,
        options: retryStatusList,
        key: 'retry',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '重试类型',
        type: 'select',
        components: Select,
        options: retryTypeList,
        key: 'retryType',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '重试最大次数',
        type: 'input',
        components: Input,
        key: 'maxRetryCount',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          allowClear: true,
          placeholder: '请输入',
        },
      },
      {
        label: '重试间隔时间',
        type: 'input',
        components: Input,
        key: 'retryTime',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          allowClear: true,
          placeholder: '请输入',
        },
      },
    ],
  },
  {
    infoTitle: '关联公司',
    selectInfo: '选择公司',
    list: [
      {
        span: 24,
        key: 'companyList',
      },
    ],
  },
  {
    infoTitle: '关联执行内容',
    selectInfo: '选择模块',
    list: [
      {
        span: 24,
        key: 'grabModuleList',
      },
    ],
  },
  /* {
    infoTitle: '关联流程',
    process: '关联流程',
    list: [
      {
        span: 24,
        key: 'process',
      },
    ],
  }, */
];

export const LINKED_FORM_ITEM_LIST = [
  {
    infoTitle: '基本信息',
    list: [
      {
        label: '任务编号',
        type: 'input',
        components: Input,
        key: 'taskId',
        width: '297px',
        // rules: [{ required: true, message: '请输入' }],
        attrs: {
          disabled: true,
        },
      },
      {
        label: '执行器类型',
        type: 'select',
        components: Select,
        options: actuatorTypeList,
        key: 'actuatorTypeCode',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          disabled: true,
        },
      },
      {
        label: '交易中心名称',
        type: 'select',
        components: Select,
        options: tradingCenterNameList,
        key: 'tradingCenterCode',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          disabled: true,
        },
      },
      {
        label: '任务名称',
        type: 'input',
        components: Input,
        key: 'taskName',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          allowClear: true,
          placeholder: '请输入',
        },
      },
      {
        label: '优先等级',
        type: 'select',
        components: Select,
        options: priorityLevelList,
        key: 'priority',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '超时时间',
        type: 'input',
        components: Input,
        key: 'timeOut',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          allowClear: true,
          placeholder: '请输入',
        },
      },
      {
        label: '重复周期',
        type: 'input',
        components: Input,
        key: 'cronTime',
        width: '297px',
        rules: [{ required: true, message: '请配置重复周期' }],
        attrs: {
          disabled: true,
        },
      },
      /* {
        label: '入库标识',
        type: 'input',
        components: Input,
        key: 'dataProcess',
        width: '297px',
        attrs: {
          placeholder: '请输入',
          allowClear: true,
        },
      }, */
      {
        label: '数据处理状态',
        type: 'select',
        components: Select,
        options: dataStateList,
        key: 'valid',
        rules: [{ required: true, message: '请选择' }],
        width: '297px',
        attrs: {
          placeholder: '请选择',
          allowClear: true,
        },
      },
      {
        label: '表名',
        type: 'input',
        rules: [{ required: true, message: '请输入' }],
        components: Input,
        key: 'dataName',
        width: '297px',
        attrs: {
          placeholder: '请输入',
          allowClear: true,
        },
      },
      {
        label: '校验字段',
        type: 'input',
        components: Input,
        rules: [{ required: true, message: '请输入' }],
        key: 'checkField',
        width: '297px',
        attrs: {
          placeholder: '请输入',
          allowClear: true,
        },
      },
      {
        label: '唯一性字段',
        type: 'input',
        rules: [{ required: true, message: '请输入' }],
        components: Input,
        key: 'deleteField',
        width: '297px',
        attrs: {
          placeholder: '请输入',
          allowClear: true,
        },
      },
      {
        label: '入库表名',
        type: 'select',
        components: Select,
        options: clickHouseList,
        key: 'clickhouseName',
        rules: [{ required: true, message: '请选择' }],
        width: '297px',
        attrs: {
          placeholder: '请选择',
          allowClear: true,
        },
      },
      {
        label: '备注',
        type: 'textArea',
        components: TextArea,
        key: 'taskDesc',
        width: '297px',
        height: '34px',
        attrs: {
          placeholder: '请输入',
        },
      },
      {
        label: '执行脚本',
        type: 'textArea',
        components: TextArea,
        key: 'executeScript',
        minWidth: '1064px',
        attrs: {
          placeholder: '请输入',
          autoSize: { minRows: 3, maxRows: 8 },
        },
      },
    ],
  },
  {
    infoTitle: '重试信息',
    list: [
      {
        label: '是否重试',
        type: 'select',
        components: Select,
        options: retryStatusList,
        key: 'retry',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '重试类型',
        type: 'select',
        components: Select,
        options: retryTypeList,
        key: 'retryTypeCode',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          allowClear: true,
          placeholder: '请选择',
        },
      },
      {
        label: '重试最大次数',
        type: 'input',
        components: Input,
        key: 'maxRetryCount',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          allowClear: true,
          placeholder: '请输入',
        },
      },
      {
        label: '重试间隔时间',
        type: 'input',
        components: Input,
        key: 'retryTime',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          allowClear: true,
          placeholder: '请输入',
        },
      },
    ],
  },
  {
    infoTitle: '关联公司',
    selectInfo: '选择公司',
    list: [
      {
        span: 24,
        key: 'companyList',
      },
    ],
  },
  {
    infoTitle: '关联执行内容',
    selectInfo: '选择模块',
    list: [
      {
        span: 24,
        key: 'grabModuleList',
      },
    ],
  },
  /* {
    infoTitle: '关联流程',
    process: '关联流程',
    list: [
      {
        span: 24,
        key: 'process',
      },
    ],
  }, */
];

export const VIEW_LINKED_FORM_ITEM_LIST = [
  {
    infoTitle: '基本信息',
    list: [
      {
        label: '任务编号',
        type: 'input',
        components: Input,
        key: 'taskId',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '执行器类型',
        type: 'input',
        components: Input,
        key: 'actuatorTypeName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '交易中心名称',
        type: 'input',
        components: Input,
        key: 'tradingCenterName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '任务名称',
        type: 'input',
        components: Input,
        key: 'taskName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '优先等级',
        type: 'input',
        components: Input,
        key: 'priority',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '超时时间',
        type: 'input',
        components: Input,
        key: 'timeOut',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '重复周期',
        type: 'input',
        components: Input,
        key: 'cronTime',
        padding: 'unset',
        width: '297px',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '数据处理状态',
        type: 'input',
        components: Input,
        key: 'valid',
        padding: 'unset',
        width: '297px',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '表名',
        type: 'input',
        components: Input,
        key: 'dataName',
        padding: 'unset',
        width: '297px',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '校验字段',
        type: 'input',
        components: Input,
        key: 'checkField',
        padding: 'unset',
        width: '297px',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '唯一性字段',
        type: 'input',
        components: Input,
        key: 'deleteField',
        padding: 'unset',
        width: '297px',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '入库表名',
        type: 'input',
        components: Input,
        key: 'clickhouseName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '备注',
        type: 'input',
        components: Input,
        key: 'taskDesc',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '执行脚本',
        type: 'textArea',
        components: TextArea,
        key: 'executeScript',
        minWidth: '1064px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
          autoSize: { minRows: 3, maxRows: 8 },
        },
      },
    ],
  },
  {
    infoTitle: '重试信息',
    list: [
      {
        label: '是否重试',
        type: 'input',
        components: Input,
        key: 'retry',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '重试类型',
        type: 'input',
        components: Input,
        key: 'retryTypeName',
        width: '297px',
        rules: [{ required: true, message: '请选择' }],
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '重试最大次数',
        type: 'input',
        components: Input,
        key: 'maxRetryCount',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '重试间隔时间',
        type: 'input',
        components: Input,
        key: 'retryTime',
        width: '297px',
        rules: [{ required: true, message: '请输入' }],
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
    ],
  },
  {
    infoTitle: '关联公司',
    selectInfo: '选择公司',
    list: [
      {
        span: 24,
        key: 'companyList',
      },
    ],
  },
  {
    infoTitle: '关联执行内容',
    selectInfo: '选择模块',
    list: [
      {
        span: 24,
        key: 'grabModuleList',
      },
    ],
  },
  /*  {
    infoTitle: '关联流程',
    process: '关联流程',
    list: [
      {
        span: 24,
        key: 'process',
        attrs: {
          readOnly: true,
          bordered: false,
          style: {
            padding: 'unset',
          },
        },
      },
    ],
  }, */
];

export const INSTANCE_VIEW_LINKED_FORM_ITEM_LIST = [
  {
    infoTitle: '基本信息',
    list: [
      {
        label: '任务编号',
        type: 'input',
        components: Input,
        key: 'taskId',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '任务名称',
        type: 'input',
        components: Input,
        key: 'taskName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '执行器类型',
        type: 'input',
        components: Input,
        key: 'actuatorTypeName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '交易中心名称',
        type: 'input',
        components: Input,
        key: 'tradingCenterName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '优先等级',
        type: 'input',
        components: Input,
        key: 'priority',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '超时时间',
        type: 'input',
        components: Input,
        key: 'timeOut',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '任务抓取时间',
        type: 'input',
        components: Input,
        key: 'dataGrabDate',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '任务状态',
        type: 'input',
        components: Input,
        key: 'taskState',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '任务参数',
        type: 'input',
        components: Input,
        key: 'taskParam',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '执行脚本',
        type: 'textArea',
        components: TextArea,
        key: 'executeScript',
        minWidth: '1064px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
          autoSize: { minRows: 3, maxRows: 8 },
        },
      },
    ],
  },
  {
    infoTitle: '重试信息',
    list: [
      {
        label: '是否重试',
        type: 'input',
        components: Input,
        key: 'retry',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '重试类型',
        type: 'input',
        components: Input,
        key: 'retryTypeName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '重试最大次数',
        type: 'input',
        components: Input,
        key: 'maxRetryCount',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '重试间隔时间',
        type: 'input',
        components: Input,
        key: 'retryTime',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      /* {
        label: '已重试次数',
        type: 'input',
        components: Input,
        key: 'retryCount',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      }, */
    ],
  },
  {
    infoTitle: '关联信息',
    list: [
      {
        label: '公司名称',
        type: 'input',
        components: Input,
        key: 'companyName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      {
        label: '执行模块',
        type: 'input',
        components: Input,
        key: 'grabModule',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      },
      /* {
        label: '流程名称',
        type: 'input',
        components: Input,
        key: 'processName',
        width: '297px',
        padding: 'unset',
        attrs: {
          readOnly: true,
          bordered: false,
        },
      }, */
    ],
  },
  {
    infoTitle: '执行信息',
    taskLog: '任务日志',
    list: [
      {
        span: 24,
        key: 'taskLog',
      },
    ],
  },
];
